package com.wu.qqserver.service;

import com.wu.qqcommon.Message;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;

public class OffLineNewsToOneUserService {

    private static ConcurrentHashMap<String, ArrayList<Message>> offNews = new ConcurrentHashMap<String, ArrayList<Message>>();

    //将某个用户的所有离线消息加入集合，，
    //注意------当我们要加的时候 一定要给message设置一个消息类型 ，因为用户线程只有知道消息类型才会进行业务处理
    public static void addOffNews(String userId,Message message){
        ArrayList<Message> messageArrayList = offNews.get(userId);
        if (messageArrayList==null){
            messageArrayList = new ArrayList<Message>();
        }
        messageArrayList.add(message);
        offNews.put(userId, messageArrayList);
    }

    //通过Userid将某个线程取出
    public static ArrayList<Message> getOffNews(String userId){
        return offNews.get(userId);
    }

    public static void remove(String userId){
        offNews.remove(userId);
    }

    public static boolean userIdIsEmpty(String userId){
        return offNews.containsKey(userId);
    }

}
